convert vcf to dynamic Format. (#1210)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Thu, 9 Nov 2023 00:43:17 +0000 (17:43 -0700)
committerGitHub <noreply@github.com>
Thu, 9 Nov 2023 00:43:17 +0000 (17:43 -0700)
CMakeLists.txt
vcf.cc
vcf.h [new file with mode: 0644]
vecs.cc

index 315137eefba390b7c462e00ad1503939879f38b7..fcbb1dc2068e07435b6efd1b277bbe34afc676b9 100644 (file)
@@ -238,6 +238,7 @@ set(HEADERS
   text.h
   unicsv.h
   units.h
+  vcf.h
   vecs.h
   xcsv.h
   xmlgeneric.h
diff --git a/vcf.cc b/vcf.cc
index fd3e90844a1b0f5e76c8c7882e79717e0e84b110..4775e753fd22d52e1ab63dfffecc5d901f1b9880 100644 (file)
--- a/vcf.cc
+++ b/vcf.cc
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
 
+#include "vcf.h"
+
 #include <cmath>       // for fabs
 #include <cstdlib>     // for abs
 
 #include <QString>     // for QString
-#include <QVector>     // for QVector
 #include <Qt>          // for CaseInsensitive
 
 #include "defs.h"
-#include "gbfile.h"    // for gbfprintf, gbfputs, gbfclose, gbfopen, gbfile
+#include "gbfile.h"    // for gbfprintf, gbfputs, gbfclose, gbfopen
 #include "geocache.h"  // for Geocache, Geocache::UtfString
 
 
-static gbfile* file_out;
-
-static char* vcf_encrypt = nullptr;
-
 #define MYNAME "VCF"
 
-static
-QVector<arglist_t> vcf_args = {
-  {
-    "encrypt", &vcf_encrypt,
-    "Encrypt hints using ROT13", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
-  },
-};
 
-static void
-wr_init(const QString& fname)
+void
+VcfFormat::wr_init(const QString& fname)
 {
   file_out = gbfopen(fname, "w", MYNAME);
 }
 
-static void
-wr_deinit()
+void
+VcfFormat::wr_deinit()
 {
   gbfclose(file_out);
 }
@@ -60,8 +50,8 @@ wr_deinit()
  * Print a possibly empty input string, replacing newlines with escaped
  * newlines as we go.
  */
-static void
-vcf_print_utf(const Geocache::UtfString* s)
+void
+VcfFormat::vcf_print_utf(const Geocache::UtfString* s)
 {
   if (nullptr == s) {
     return;
@@ -77,8 +67,8 @@ vcf_print_utf(const Geocache::UtfString* s)
   gbfputs(stripped_html, file_out);
 }
 
-static void
-vcf_print(const char* s)
+void
+VcfFormat::vcf_print(const char* s)
 {
   if (!s) {
     return;
@@ -90,14 +80,14 @@ vcf_print(const char* s)
   gbfputs(cleaned, file_out);
 }
 
-static void
-vcf_print(const QString& s)
+void
+VcfFormat::vcf_print(const QString& s)
 {
   vcf_print(CSTR(s));
 }
 
-static void
-vcf_disp(const Waypoint* wpt)
+void
+VcfFormat::vcf_disp(const Waypoint* wpt)
 {
   int lonint = abs((int) wpt->longitude);
   int latint = abs((int) wpt->latitude);
@@ -126,23 +116,10 @@ vcf_disp(const Waypoint* wpt)
   gbfprintf(file_out, "\nEND:VCARD\n");
 }
 
-static void
-data_write()
+void VcfFormat::write()
 {
-  waypt_disp_all(vcf_disp);
+  auto vcf_disp_lambda = [this](const Waypoint* waypointp)->void {
+    vcf_disp(waypointp);
+  };
+  waypt_disp_all(vcf_disp_lambda);
 }
-
-
-ff_vecs_t vcf_vecs = {
-  ff_type_file,
-  { ff_cap_write, ff_cap_none, ff_cap_none},
-  nullptr,
-  wr_init,
-  nullptr,
-  wr_deinit,
-  nullptr,
-  data_write,
-  nullptr,
-  &vcf_args,
-  NULL_POS_OPS
-};
diff --git a/vcf.h b/vcf.h
new file mode 100644 (file)
index 0000000..7a4a531
--- /dev/null
+++ b/vcf.h
@@ -0,0 +1,79 @@
+/*
+    Output only format for Vcard format, VCF
+
+    Copyright (C) 2005 Robert Lipe, robertlipe+source@gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*/
+#ifndef VCF_H_INCLUDED_
+#define VCF_H_INCLUDED_
+
+#include <QString>     // for QString
+#include <QVector>     // for QVector
+
+#include "defs.h"
+#include "format.h"    // for Format
+#include "gbfile.h"    // for gbfile
+#include "geocache.h"  // for Geocache
+
+
+class VcfFormat : public Format
+{
+public:
+  using Format::Format;
+
+  QVector<arglist_t>* get_args() override
+  {
+    return &vcf_args;
+  }
+
+  ff_type get_type() const override
+  {
+    return ff_type_file;
+  }
+
+  QVector<ff_cap> get_cap() const override
+  {
+    return {ff_cap_write, ff_cap_none, ff_cap_none};
+  }
+
+  void wr_init(const QString& fname) override;
+  void write() override;
+  void wr_deinit() override;
+
+private:
+
+  /* Member Functions */
+
+  void vcf_print_utf(const Geocache::UtfString* s);
+  void vcf_print(const char* s);
+  void vcf_print(const QString& s);
+  void vcf_disp(const Waypoint* wpt);
+
+  /* Data Members */
+
+  gbfile* file_out{};
+
+  char* vcf_encrypt = nullptr;
+
+  QVector<arglist_t> vcf_args = {
+    {
+      "encrypt", &vcf_encrypt,
+      "Encrypt hints using ROT13", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
+    },
+  };
+
+};
+#endif // VCF_H_INCLUDED_
diff --git a/vecs.cc b/vecs.cc
index 10c5fca2f60a8e405ca6a1f315d3154318483717..944e863ab99229ded4eb89f7cf618b5b049b9d48 100644 (file)
--- a/vecs.cc
+++ b/vecs.cc
@@ -68,8 +68,9 @@
 #include "subrip.h"            // for SubripFormat
 #include "text.h"              // for TextFormat
 #include "unicsv.h"            // for UnicsvFormat
+#include "vcf.h"               // for VcfFormat
 #include "xcsv.h"              // for XcsvStyle, XcsvFormat
-#include "googletakeout.h"    // for GoogleTakeoutFormat
+#include "googletakeout.h"     // for GoogleTakeoutFormat
 
 
 extern ff_vecs_t geo_vecs;
@@ -86,7 +87,6 @@ extern ff_vecs_t mtk_m241_vecs;
 extern ff_vecs_t mtk_m241_fvecs;
 #endif // MAXIMAL_ENABLED
 #if MAXIMAL_ENABLED
-extern ff_vecs_t vcf_vecs;
 extern ff_vecs_t gtm_vecs;
 #if CSVFMTS_ENABLED
 extern ff_vecs_t garmin_txt_vecs;
@@ -136,7 +136,6 @@ struct Vecs::Impl {
   LegacyFormat mtk_m241_ffmt {mtk_m241_fvecs};
 #endif // MAXIMAL_ENABLED
 #if MAXIMAL_ENABLED
-  LegacyFormat vcf_fmt {vcf_vecs};
   UnicsvFormat unicsv_fmt;
   LegacyFormat gtm_fmt {gtm_vecs};
 #if CSVFMTS_ENABLED
@@ -317,11 +316,12 @@ struct Vecs::Impl {
 #endif // MAXIMAL_ENABLED
 #if MAXIMAL_ENABLED
     {
-      &vcf_fmt,
+      nullptr,
       "vcard",
       "Vcard Output (for iPod)",
       "vcf",
       nullptr,
+      &fmtfactory<VcfFormat>
     },
     {
       &unicsv_fmt,